package com.agree.utils;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;



/*import com.vandagroup.common.bean.BaseBean;
import com.vandagroup.engine.main.MainResource;
import com.vandagroup.hibernate.PersistentTool;
import com.vandagroup.hibernate.databean.PageRoll;*/

/**
 * 加密工具类
 * @author WangQiang
 *d
 */
public class SSLUtils {
	static Logger logs = Logger.getLogger(SSLUtils.class);
	private static String privateKey = "e10adc3949ba59abbe56e057f20f883e";
	
	/**
	 * 么钥缓存
	 * @author WangQiang
	 *
	 */

	
	public static String encryptMsg(String date,String origMsg, String customNum) throws SSLException, NoSuchAlgorithmException, InvalidKeyException{
		String encryptMsg = null;
		if( StringUtils.isBlank(privateKey)){
	        	throw new SSLException("未找到交易私钥");
       }
	
		
	// 取得密钥
      byte[] keyByte = (date+customNum+privateKey).getBytes();
   // 生成MAC对象
      Mac mac = Mac.getInstance( "HMACMD5" );
      SecretKeySpec sks = new SecretKeySpec( keyByte , "HMACMD5" );
      mac.init( sks );
     // 传入要计算验证码的字符串  
      mac.update( origMsg.getBytes() );
   // 计算验证码
      byte[] certifyCode = mac.doFinal();
      encryptMsg = new String(Hex.encodeHex(certifyCode));
		return encryptMsg;
	}
/*public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException, SSLException {
	String changePassowrd=MD5Utils.string2MD5("123456");
	
}*/
}
